home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ccrptmr / ftimerte.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-03-20  |  17.4 KB  |  527 lines

  1. VERSION 5.00
  2. Begin VB.Form frmTimerTest 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "ccrpTmr.dll Testbed"
  5.    ClientHeight    =   6030
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4740
  9.    Icon            =   "FTimerTest.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   6030
  14.    ScaleWidth      =   4740
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton cmdFrequency 
  17.       Caption         =   "Set"
  18.       Height          =   315
  19.       Left            =   3840
  20.       TabIndex        =   32
  21.       ToolTipText     =   "Sets the frequency used internally by ccrpTimers."
  22.       Top             =   4200
  23.       Width           =   735
  24.    End
  25.    Begin VB.TextBox txtFrequency 
  26.       Height          =   315
  27.       Left            =   3060
  28.       TabIndex        =   31
  29.       Text            =   "txtFrequency"
  30.       Top             =   4200
  31.       Width           =   615
  32.    End
  33.    Begin VB.Frame Frame4 
  34.       Caption         =   "Countdown Instance:"
  35.       Height          =   795
  36.       Left            =   120
  37.       TabIndex        =   14
  38.       Top             =   2400
  39.       Width           =   4455
  40.       Begin VB.CheckBox chkEnabled 
  41.          Caption         =   "Enabled"
  42.          Height          =   255
  43.          Index           =   3
  44.          Left            =   3420
  45.          TabIndex        =   18
  46.          ToolTipText     =   "Initiates a countdown by toggling Enabled property"
  47.          Top             =   360
  48.          Width           =   915
  49.       End
  50.       Begin VB.TextBox txtCountdown1 
  51.          Height          =   315
  52.          Left            =   1260
  53.          TabIndex        =   16
  54.          Text            =   "txtCountdown1"
  55.          ToolTipText     =   "Number of milliseconds countdown will last"
  56.          Top             =   300
  57.          Width           =   735
  58.       End
  59.       Begin VB.CommandButton cmdCountdown1 
  60.          Caption         =   "Set Duration"
  61.          Height          =   315
  62.          Left            =   2100
  63.          TabIndex        =   17
  64.          ToolTipText     =   "Sets number of milliseconds countdown should last"
  65.          Top             =   300
  66.          Width           =   1155
  67.       End
  68.       Begin VB.Label lblCountdown1 
  69.          BorderStyle     =   1  'Fixed Single
  70.          Caption         =   "Seconds"
  71.          Height          =   315
  72.          Left            =   120
  73.          TabIndex        =   15
  74.          Top             =   300
  75.          Width           =   1035
  76.       End
  77.    End
  78.    Begin VB.Frame Frame3 
  79.       Caption         =   "Timer ""OneShot"" Instance:"
  80.       Height          =   795
  81.       Left            =   120
  82.       TabIndex        =   9
  83.       Top             =   1500
  84.       Width           =   4455
  85.       Begin VB.CommandButton Command1 
  86.          Caption         =   "Set Interval"
  87.          Height          =   315
  88.          Left            =   2100
  89.          TabIndex        =   12
  90.          ToolTipText     =   "Sets number of milliseconds before the OneShot event"
  91.          Top             =   300
  92.          Width           =   1155
  93.       End
  94.       Begin VB.CheckBox chkEnabled 
  95.          Caption         =   "Enabled"
  96.          Height          =   255
  97.          Index           =   2
  98.          Left            =   3420
  99.          TabIndex        =   13
  100.          ToolTipText     =   "Initiates a OneShot timer by toggling Enabled property"
  101.          Top             =   360
  102.          Width           =   915
  103.       End
  104.       Begin VB.TextBox txtTimer3 
  105.          Height          =   315
  106.          Left            =   1260
  107.          TabIndex        =   11
  108.          Text            =   "txtTimer3"
  109.          ToolTipText     =   "Number of milliseconds Interval property of Timer3 is set to"
  110.          Top             =   300
  111.          Width           =   735
  112.       End
  113.       Begin VB.Label lblTimer3 
  114.          BorderStyle     =   1  'Fixed Single
  115.          Caption         =   "lblTimer3"
  116.          Height          =   315
  117.          Left            =   120
  118.          TabIndex        =   10
  119.          Top             =   300
  120.          Width           =   1035
  121.       End
  122.    End
  123.    Begin VB.CommandButton cmdExit 
  124.       Cancel          =   -1  'True
  125.       Caption         =   "Exit"
  126.       Height          =   315
  127.       Left            =   3060
  128.       TabIndex        =   34
  129.       Top             =   5460
  130.       Width           =   1515
  131.    End
  132.    Begin VB.Frame Frame2 
  133.       Caption         =   "StopWatch Instance:"
  134.       Height          =   795
  135.       Left            =   120
  136.       TabIndex        =   19
  137.       Top             =   3300
  138.       Width           =   4455
  139.       Begin VB.CommandButton cmdStopWatch1 
  140.          Caption         =   "Reset"
  141.          Height          =   315
  142.          Index           =   1
  143.          Left            =   3300
  144.          TabIndex        =   22
  145.          ToolTipText     =   "Resets StopWatch1 elapsed time value to zero"
  146.          Top             =   300
  147.          Width           =   975
  148.       End
  149.       Begin VB.CommandButton cmdStopWatch1 
  150.          Caption         =   "Elapsed"
  151.          Height          =   315
  152.          Index           =   0
  153.          Left            =   2100
  154.          TabIndex        =   21
  155.          ToolTipText     =   "Displays Elapsed time since StopWatch1 was reset"
  156.          Top             =   300
  157.          Width           =   975
  158.       End
  159.       Begin VB.Label lblStopWatch 
  160.          BorderStyle     =   1  'Fixed Single
  161.          Caption         =   " 0 ms"
  162.          Height          =   315
  163.          Left            =   120
  164.          TabIndex        =   20
  165.          Top             =   300
  166.          Width           =   1035
  167.       End
  168.    End
  169.    Begin VB.Frame Frame1 
  170.       Caption         =   "Two Timer ""Periodic"" Instances:"
  171.       Height          =   1275
  172.       Left            =   120
  173.       TabIndex        =   0
  174.       Top             =   120
  175.       Width           =   4455
  176.       Begin VB.CommandButton cmdTimer2 
  177.          Caption         =   "Set Interval"
  178.          Height          =   315
  179.          Left            =   2100
  180.          TabIndex        =   7
  181.          ToolTipText     =   "Sets number of milliseconds between Timer events"
  182.          Top             =   780
  183.          Width           =   1155
  184.       End
  185.       Begin VB.CommandButton cmdTimer1 
  186.          Caption         =   "Set Interval"
  187.          Height          =   315
  188.          Left            =   2100
  189.          TabIndex        =   3
  190.          ToolTipText     =   "Sets number of milliseconds between Timer events"
  191.          Top             =   300
  192.          Width           =   1155
  193.       End
  194.       Begin VB.TextBox txtTimer2 
  195.          Height          =   315
  196.          Left            =   1260
  197.          TabIndex        =   6
  198.          Text            =   "txtTimer2"
  199.          ToolTipText     =   "Number of milliseconds between Timer events"
  200.          Top             =   780
  201.          Width           =   735
  202.       End
  203.       Begin VB.TextBox txtTimer1 
  204.          Height          =   315
  205.          Left            =   1260
  206.          TabIndex        =   2
  207.          Text            =   "txtTimer1"
  208.          ToolTipText     =   "Number of milliseconds between Timer events"
  209.          Top             =   300
  210.          Width           =   735
  211.       End
  212.       Begin VB.CheckBox chkEnabled 
  213.          Caption         =   "Enabled"
  214.          Height          =   255
  215.          Index           =   0
  216.          Left            =   3420
  217.          TabIndex        =   4
  218.          ToolTipText     =   "Toggles Enabled property of ccrpTimer class"
  219.          Top             =   360
  220.          Value           =   1  'Checked
  221.          Width           =   915
  222.       End
  223.       Begin VB.CheckBox chkEnabled 
  224.          Caption         =   "Enabled"
  225.          Height          =   255
  226.          Index           =   1
  227.          Left            =   3420
  228.          TabIndex        =   8
  229.          ToolTipText     =   "Toggles Enabled property of ccrpTimer class"
  230.          Top             =   840
  231.          Value           =   1  'Checked
  232.          Width           =   915
  233.       End
  234.       Begin VB.Label lblTimer1 
  235.          BorderStyle     =   1  'Fixed Single
  236.          Caption         =   "Seconds"
  237.          Height          =   315
  238.          Left            =   120
  239.          TabIndex        =   1
  240.          Top             =   300
  241.          Width           =   1035
  242.       End
  243.       Begin VB.Label lblTimer2 
  244.          BorderStyle     =   1  'Fixed Single
  245.          Caption         =   "Quarters"
  246.          Height          =   315
  247.          Left            =   120
  248.          TabIndex        =   5
  249.          Top             =   780
  250.          Width           =   1035
  251.       End
  252.    End
  253.    Begin VB.CommandButton cmdAbout 
  254.       Caption         =   "About..."
  255.       Default         =   -1  'True
  256.       Height          =   315
  257.       Left            =   3060
  258.       TabIndex        =   33
  259.       Top             =   5040
  260.       Width           =   1515
  261.    End
  262.    Begin VB.Label lblFreqCap 
  263.       Alignment       =   1  'Right Justify
  264.       AutoSize        =   -1  'True
  265.       Caption         =   "Library Frequency::"
  266.       Height          =   195
  267.       Left            =   345
  268.       TabIndex        =   23
  269.       Top             =   4260
  270.       Width           =   1350
  271.    End
  272.    Begin VB.Label lblFreq 
  273.       BorderStyle     =   1  'Fixed Single
  274.       Caption         =   "lblFreq"
  275.       Height          =   315
  276.       Left            =   1800
  277.       TabIndex        =   24
  278.       Top             =   4200
  279.       Width           =   975
  280.    End
  281.    Begin VB.Label lblRes 
  282.       BorderStyle     =   1  'Fixed Single
  283.       Caption         =   "lblRes"
  284.       Height          =   315
  285.       Left            =   1800
  286.       TabIndex        =   26
  287.       Top             =   4620
  288.       Width           =   975
  289.    End
  290.    Begin VB.Label lblResCap 
  291.       Alignment       =   1  'Right Justify
  292.       AutoSize        =   -1  'True
  293.       Caption         =   "System Resolution:"
  294.       Height          =   195
  295.       Left            =   345
  296.       TabIndex        =   25
  297.       Top             =   4680
  298.       Width           =   1350
  299.    End
  300.    Begin VB.Label lblMinCap 
  301.       Alignment       =   1  'Right Justify
  302.       AutoSize        =   -1  'True
  303.       Caption         =   "Minimum Resolution:"
  304.       Height          =   195
  305.       Left            =   240
  306.       TabIndex        =   27
  307.       Top             =   5100
  308.       Width           =   1455
  309.    End
  310.    Begin VB.Label lblMaxCap 
  311.       Alignment       =   1  'Right Justify
  312.       AutoSize        =   -1  'True
  313.       Caption         =   "Maximum Resolution:"
  314.       Height          =   195
  315.       Left            =   195
  316.       TabIndex        =   29
  317.       Top             =   5520
  318.       Width           =   1500
  319.    End
  320.    Begin VB.Label lblMax 
  321.       BorderStyle     =   1  'Fixed Single
  322.       Caption         =   "lblMax"
  323.       Height          =   315
  324.       Left            =   1800
  325.       TabIndex        =   30
  326.       Top             =   5460
  327.       Width           =   975
  328.    End
  329.    Begin VB.Label lblMin 
  330.       BorderStyle     =   1  'Fixed Single
  331.       Caption         =   "lblMin"
  332.       Height          =   315
  333.       Left            =   1800
  334.       TabIndex        =   28
  335.       Top             =   5040
  336.       Width           =   975
  337.    End
  338. Attribute VB_Name = "frmTimerTest"
  339. Attribute VB_GlobalNameSpace = False
  340. Attribute VB_Creatable = False
  341. Attribute VB_PredeclaredId = True
  342. Attribute VB_Exposed = False
  343. Option Explicit
  344. Private WithEvents Timer1 As ccrpTimer
  345. Attribute Timer1.VB_VarHelpID = -1
  346. Private WithEvents Timer2 As ccrpTimer
  347. Attribute Timer2.VB_VarHelpID = -1
  348. Private WithEvents Timer3 As ccrpTimer
  349. Attribute Timer3.VB_VarHelpID = -1
  350. Private WithEvents Countdown1 As ccrpCountdown
  351. Attribute Countdown1.VB_VarHelpID = -1
  352. Private StopWatch1 As ccrpStopWatch
  353. Private Sub chkEnabled_Click(Index As Integer)
  354.    Select Case Index
  355.       Case 0
  356.          Timer1.Enabled = CBool(chkEnabled(Index))
  357.       Case 1
  358.          Timer2.Enabled = CBool(chkEnabled(Index))
  359.       Case 2
  360.          Timer3.Interval = Val(txtTimer3.Text)
  361.          Timer3.Enabled = CBool(chkEnabled(Index))
  362.          If CBool(chkEnabled(Index)) Then
  363.             lblTimer3.Caption = " Waiting"
  364.          Else
  365.             lblTimer3.Caption = ""
  366.          End If
  367.       Case 3
  368.          Countdown1.Enabled = CBool(chkEnabled(Index).Value)
  369.    End Select
  370. End Sub
  371. Private Sub cmdAbout_Click()
  372.    Timer1.About
  373. End Sub
  374. Private Sub cmdCountdown1_Click()
  375.    Countdown1.Duration = txtCountdown1.Text
  376. End Sub
  377. Private Sub cmdExit_Click()
  378.    Unload Me
  379. End Sub
  380. Private Sub cmdReset_Click()
  381.    StopWatch1.Reset
  382.    lblStopWatch.Caption = " " & Format(StopWatch1.Elapsed, "#,##0") & " ms"
  383. End Sub
  384. Private Sub cmdFrequency_Click()
  385.    With Timer1.Stats
  386.       .Frequency = Val(txtFrequency.Text)
  387.       lblRes.Caption = " " & Format(.Resolution, "#,##0") & " ms"
  388.       lblMin.Caption = " " & Format(.MinimumResolution, "#,##0") & " ms"
  389.       lblMax.Caption = " " & Format(.MaximumResolution, "#,##0") & " ms"
  390.       lblFreq.Caption = " " & Format(.Frequency, "#,##0") & " ms"
  391.    End With
  392. End Sub
  393. Private Sub cmdStopWatch1_Click(Index As Integer)
  394.    If Index = 1 Then ' Reset before displaying elapsed time
  395.       StopWatch1.Reset
  396.    End If
  397.    lblStopWatch.Caption = " " & Format(StopWatch1.Elapsed, "#,##0") & " ms"
  398. End Sub
  399. Private Sub cmdTimer1_Click()
  400.    Timer1.Interval = Val(txtTimer1.Text)
  401. End Sub
  402. Private Sub cmdTimer2_Click()
  403.    Timer2.Interval = Val(txtTimer2.Text)
  404. End Sub
  405. Private Sub Countdown1_Tick(ByVal TimeRemaining As Long)
  406.    lblCountdown1.Caption = " " & Format(TimeRemaining / 1000, "0.0") & " sec"
  407. End Sub
  408. Private Sub Countdown1_Timer()
  409.    chkEnabled(3).Value = Abs(Countdown1.Enabled)
  410. End Sub
  411. Private Sub Form_Load()
  412.    Set Timer1 = New ccrpTimer
  413.    Set Timer2 = New ccrpTimer
  414.    Set Timer3 = New ccrpTimer
  415.    Set StopWatch1 = New ccrpStopWatch
  416.    Set Countdown1 = New ccrpCountdown
  417.    With Timer1
  418.       .EventType = TimerPeriodic
  419.       .Interval = 1000
  420.       .Stats.Frequency = 20
  421.       .Enabled = True
  422.       txtTimer1.Text = .Interval
  423.       lblTimer1.Caption = " 0"
  424.    End With
  425.    With Timer2
  426.       .EventType = TimerPeriodic
  427.       .Interval = 250
  428.       .Enabled = True
  429.       txtTimer2.Text = .Interval
  430.       lblTimer2.Caption = " 0"
  431.    End With
  432.    With Timer3
  433.       .EventType = TimerOneShot
  434.       .Interval = 2000       ' 2 seconds
  435.       .Enabled = False
  436.       txtTimer3.Text = .Interval
  437.       lblTimer3.Caption = ""
  438.    End With
  439.    With Countdown1
  440.       .Duration = 5000       ' 5 seconds
  441.       .Interval = 100        ' 0.1 seconds
  442.       .Enabled = False
  443.       lblCountdown1.Caption = ""
  444.       txtCountdown1.Text = .Duration
  445.    End With
  446.    Me.Icon = Nothing
  447.    With Timer1.Stats
  448.       lblRes.Caption = " " & Format(.Resolution, "#,##0") & " ms"
  449.       lblMin.Caption = " " & Format(.MinimumResolution, "#,##0") & " ms"
  450.       lblMax.Caption = " " & Format(.MaximumResolution, "#,##0") & " ms"
  451.       lblFreq.Caption = " " & Format(.Frequency, "#,##0") & " ms"
  452.       txtFrequency.Text = .Frequency
  453.    End With
  454. End Sub
  455. Private Sub Form_Unload(Cancel As Integer)
  456.    ' Nice stable shutdown. Shouldn't be necessary, but
  457.    ' is good form. Can prevent needless debugging.
  458.    Timer1.Enabled = False
  459.    Set Timer1 = Nothing
  460.    Timer2.Enabled = False
  461.    Set Timer2 = Nothing
  462.    Timer3.Enabled = False
  463.    Set Timer3 = Nothing
  464.    Set StopWatch1 = Nothing
  465.    Countdown1.Enabled = False
  466.    Set Countdown1 = Nothing
  467. End Sub
  468. Private Sub Timer1_Timer(ByVal Milliseconds As Long)
  469.    Static Ticks As Long
  470.    ' Updating the display more often than every 10ms can blow
  471.    ' Win95's 16-bit GDI to shreds -- hardlock or system reset.
  472.    Ticks = Ticks + Milliseconds
  473.    If Timer1.Interval >= 10 Then
  474.       lblTimer1.Caption = " " & Format(Ticks, "#,##0")
  475.    ElseIf (Ticks Mod 10) = 0 Then
  476.       lblTimer1.Caption = " " & Format(Ticks, "#,##0")
  477.    End If
  478. End Sub
  479. Private Sub Timer2_Timer(ByVal Milliseconds As Long)
  480.    Static Ticks As Long
  481.    ' Updating the display more often than every 10ms can blow
  482.    ' Win95's 16-bit GDI to shreds -- hardlock or system reset.
  483.    Ticks = Ticks + Milliseconds
  484.    If Timer2.Interval >= 10 Then
  485.       lblTimer2.Caption = " " & Format(Ticks, "#,##0")
  486.    ElseIf (Ticks Mod 10) = 0 Then
  487.       lblTimer2.Caption = " " & Format(Ticks, "#,##0")
  488.    End If
  489. End Sub
  490. Private Sub Timer3_Timer(ByVal Milliseconds As Long)
  491.    Dim sw As ccrpStopWatch
  492.    Dim bc As Long
  493.    Dim i As Long
  494.    chkEnabled(2).Value = Abs(Timer3.Enabled)
  495.    lblTimer3.Caption = Format(Milliseconds, "#,##0") & " ms"
  496.    Set sw = New ccrpStopWatch
  497.    With txtTimer3
  498.       bc = .BackColor
  499.       For i = 1 To 8 Step 2
  500.          .BackColor = vbRed
  501.          Do Until sw.Elapsed > (i * 250): DoEvents: Loop
  502.          .BackColor = bc
  503.          Do Until sw.Elapsed > ((i + 1) * 250): DoEvents: Loop
  504.       Next i
  505.    End With
  506.    lblTimer3.Caption = ""
  507. End Sub
  508. Private Sub Highlight(txt As TextBox)
  509.    txt.SelStart = 0
  510.    txt.SelLength = Len(txt.Text)
  511. End Sub
  512. Private Sub txtCountdown1_GotFocus()
  513.    Call Highlight(txtCountdown1)
  514. End Sub
  515. Private Sub txtFrequency_gotfocus()
  516.    Call Highlight(txtFrequency)
  517. End Sub
  518. Private Sub txtTimer1_GotFocus()
  519.    Call Highlight(txtTimer1)
  520. End Sub
  521. Private Sub txtTimer2_GotFocus()
  522.    Call Highlight(txtTimer2)
  523. End Sub
  524. Private Sub txtTimer3_GotFocus()
  525.    Call Highlight(txtTimer3)
  526. End Sub
  527.